package com.ljy.system.marvel_sys.system.service.impl;

import com.ljy.system.marvel_sys.system.dao.DepartmentDao;
import com.ljy.system.marvel_sys.system.model.department.Department;
import com.ljy.system.marvel_sys.system.service.IDepartmentService;
import com.ljy.system.marvel_sys.common.util.dtree.CheckArr;
import com.ljy.system.marvel_sys.common.util.dtree.Dtree;
import com.ljy.system.marvel_sys.common.util.dtree.DtreeUtil;
import com.ljy.system.marvel_sys.common.util.dtree.Status;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 〈功能简述〉<br>
 *
 * @author LiJunYi
 * @create 2019/7/15
 * @since 1.0.0
 */
@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Resource
    DepartmentDao departmentDao;

    @Override
    public DtreeUtil listDepartment() {
        List<Department> departments = departmentDao.selectList(null);
        DtreeUtil dtreeUtil = new DtreeUtil();
        /*进行格式生成*/
        List<Dtree> dtrees = new ArrayList<>();
        for (Department department : departments){
            /*树形类*/
            Dtree dtree = new Dtree();
            /*复选框类*/
            CheckArr checkArr = new CheckArr();
            dtree.setId(department.getId());
            dtree.setTitle(department.getDepartmentName());
            dtree.setParentId(department.getPid());
            checkArr.setType("0");
            checkArr.setChecked("0");
            dtree.setCheckArr(checkArr);
            dtrees.add(dtree);
        }
        Status status = new Status();
        dtreeUtil.setStatus(status);
        dtreeUtil.setData(dtrees);
        return dtreeUtil;
    }
}
